import java.io.*;
import java.net.*;

public class Client {
    public static void main(String[] args) throws Exception{
        String hostname = "localhost";
        int port = 6066;

        try (Socket socket = new Socket(hostname, port);
             PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
             BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()))) {

            out.println("Hello Server");
            System.out.println(in.readLine());
        }
    }
}

import java.io.*;
import java.net.*;

public class Server {
    public static void main(String[] args) throws IOException {
        int port = 6066;
        ServerSocket serverSocket = new ServerSocket(port);

        while(true){
            try(Socket clientSocket = serverSocket.accept();
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),true);
                BufferedReader in = new BufferedReader(
                    new InputStreamReader(clientSocket.getInputStream()))){
                
                System.out.println("Client connected.");
                String inputLine;
                if((inputLine=in.readLine())!=null)
                    out.println("Server received : "+inputLine);   
            } catch(IOException e){}
        }
    }
}